const express = require('express')

const router = express.Router();

const multer = require('multer')

var name = ''

const storage = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, './images/');
  },
  filename: (req, file, cb) => {
    name = Date.now() + '-' + file.originalname
    cb(null, name);
  }
})

/**
 * 文件数据解析
 */
const upload = multer({
  //文件名会随机,并且没有后置
  // dest:'./uploads/'
  //配置上传文件名
  storage
});


/**
 * file代表 文件上传时的 key值
 */
router.post('/', upload.single('file'), (req, res, next) => {
  res.end(name);
})
module.exports = router